package com.abel.util;

import java.util.List;

import com.abel.domain.UserRole;
import com.abel.domain.types.RoleType;

public class UserTypeEvaluator {

	public static boolean isAdmin() {
		
		return verifyUserType(RoleType.ADMINUSER.getRoleType());
	}


	public static boolean isSuperAdmin() {
		
		return verifyUserType(RoleType.SUPERUSER.getRoleType());
	}


	public static boolean isAnyAdmin() {
		
		return verifyUserType(RoleType.ADMINUSER.getRoleType()) || verifyUserType(RoleType.SUPERUSER.getRoleType());
	}
	
	
	public static boolean isRegularUser() {
		
		return verifyUserType(RoleType.REGULARUSER.getRoleType());
	}
	
	
	private static boolean verifyUserType(String verify) {
		
		if (UserSessionLocator.getUserSession().getAuthPrincipal() != null) {
			List<UserRole> roles = UserSessionLocator.getUserSession().getAuthPrincipal().getRoles();
			
			for (UserRole userRole : roles) {
				if (userRole.getRole().equals(verify)) {
					return true;
				}
			}
		}
		return false;

	}
}
